using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace scomA3proj
{
    [DataContractAttribute]
    class DayStock
    {
        [DataMember]
        string name;
        [DataMember]
        decimal sum;
        [DataMember]
        int counter;
        [DataMember]
        decimal stockAvg;

        public DayStock(string name)
        {
            this.name = name;
            sum = 0;
            counter = 0;
        }

        public DayStock(string name, decimal sum)
        {
            this.name = name;
            this.sum = sum;
            counter = 1;
        }

        public void increment(decimal value)
        {
            sum += value;
            counter++;
        }
        public void calcAvg()
        {
            if (counter != 0)
                stockAvg =  sum / counter;
            else
                stockAvg=  0;
        }

        public string diffFromAvg(decimal avg)
        {
            decimal temp;
            temp = stockAvg - avg;
            if (temp >= 0)
                return "+$" + temp;
            else
                return "-$" + (-1 * temp);
        }

        public string toString(decimal avg)
        {
            return name + "  " + diffFromAvg(avg);
        }
    }
}
